import { makeExecutableSchema, addMockFunctionsToSchema } from 'graphql-tools'
import { SchemaLink } from 'apollo-link-schema'
import { typeDefs, typeResolvers } from './schema'
import mocks from '../mock'

const createExecutableSchema = () => {
  const schema = makeExecutableSchema({
    typeDefs,
    typeResolvers,
    resolverValidationOptions: {
      requireResolversForResolveType: false,
    },
  })
  addMockFunctionsToSchema({ schema, mocks, preserveResolvers: true })
  return schema
}
export default () => new SchemaLink({
  schema: createExecutableSchema(),
})
